package com.jaynux.app;

import com.jaynux.app.Horses.*;

import android.app.*;
import android.content.*;
import android.os.*;
import android.view.*;
import android.widget.*;

public class SettingActivity extends Activity implements View.OnClickListener{

	public static final int PLAY1_ACT_MESURE_REQUEST = 5;
	public static final int PLAY2_ACT_MESURE_REQUEST = 6;
	public static final int PLAY3_ACT_MESURE_REQUEST = 7;
	public static final int PLAY4_ACT_MESURE_REQUEST = 8;
	
	//오픈된 영웅을 알려주기 위한 변수
	boolean P1_row1col1Flag = false;
	boolean P1_row1col2Flag = false;
	boolean P1_row1col3Flag = false;
	boolean P1_row2col1Flag = false;
	boolean P1_row2col2Flag = true;
	boolean P1_row2col3Flag = false;
	boolean P1_row3col1Flag = false;
	boolean P1_row3col2Flag = false;
	boolean P1_row3col3Flag = false;
	
	boolean P2_row1col1Flag = false;
	boolean P2_row1col2Flag = false;
	boolean P2_row1col3Flag = false;
	boolean P2_row2col1Flag = false;
	boolean P2_row2col2Flag = true;
	boolean P2_row2col3Flag = false;
	boolean P2_row3col1Flag = false;
	boolean P2_row3col2Flag = false;
	boolean P2_row3col3Flag = false;
	
	boolean P3_row1col1Flag = false;
	boolean P3_row1col2Flag = false;
	boolean P3_row1col3Flag = false;
	boolean P3_row2col1Flag = false;
	boolean P3_row2col2Flag = true;
	boolean P3_row2col3Flag = false;
	boolean P3_row3col1Flag = false;
	boolean P3_row3col2Flag = false;
	boolean P3_row3col3Flag = false;
	
	boolean P4_row1col1Flag = false;
	boolean P4_row1col2Flag = false;
	boolean P4_row1col3Flag = false;
	boolean P4_row2col1Flag = false;
	boolean P4_row2col2Flag = true;
	boolean P4_row2col3Flag = false;
	boolean P4_row3col1Flag = false;
	boolean P4_row3col2Flag = false;
	boolean P4_row3col3Flag = false;
	
	private int DEFAULT_AG = 10;
	private int DEFAULT_SPEED = 20;
	private int DEFAULT_BOOSTER = 5;
	private int DEFAULT_DAMAGE = 5;

	private enum  hero_num{관우, 여포, 조운, 하후돈, 태희, 마초, 유비, 장비, 황충};
	private int imgHero[] = {R.drawable.g_h1, R.drawable.u_h1, R.drawable.j_h1, R.drawable.h_h1,
			R.drawable.k_h1, R.drawable.ma_cho_h1, R.drawable.yu_bi_h1, R.drawable.jang_bi_h1, R.drawable.hwang_chung_h1};
	//player button
	private Button player1Btn;
	private Button player2Btn;
	private Button player3Btn;
	private Button player4Btn;
	private Button nextBtn;
	
	//측정 버튼
	private Button mPlay1measureBtn;
	private Button mPlay2measureBtn;
	private Button mPlay3measureBtn;
	private Button mPlay4measureBtn;
	
	private TextView t_player1;//보폭 정보
	private TextView t_player2;
	private TextView t_player3;
	private TextView t_player4;
	private TextView s_player1;//스피드 정보
	private TextView s_player2;
	private TextView s_player3;
	private TextView s_player4;
	private TextView b_player1;//부스터 정보
	private TextView b_player2;
	private TextView b_player3;
	private TextView b_player4;
	private TextView d_player1;//데미지 정보
	private TextView d_player2;
	private TextView d_player3;
	private TextView d_player4;
	private TextView h_player1;//영웅 정보
	private TextView h_player2;
	private TextView h_player3;
	private TextView h_player4;

	private ImageButton player1Img;//영웅 이미지
	private ImageButton player2Img;
	private ImageButton player3Img;
	private ImageButton player4Img;

	//player들의 보폭,속도,부스터,영웅을 저장하는 변수
	private int player1_hero_option_ag =0;
	private int player1_hero_option_speed =0;
	private int player1_hero_option_booster =0;
	private int player1_hero_option_damage =0;
	private int player1_ag = DEFAULT_AG;
	private int player1_speed = DEFAULT_SPEED;
	private int player1_booster = DEFAULT_BOOSTER;
	private int player1_damage = DEFAULT_DAMAGE;
	private String player1_hero = "태희";

	private int player2_hero_option_ag =0;
	private int player2_hero_option_speed =0;
	private int player2_hero_option_booster =0;
	private int player2_hero_option_damage =0;
	private int player2_ag = DEFAULT_AG;
	private int player2_speed = DEFAULT_SPEED;
	private int player2_booster = DEFAULT_BOOSTER;
	private int player2_damage = DEFAULT_DAMAGE;
	private String player2_hero = "태희";

	private int player3_hero_option_ag =0;
	private int player3_hero_option_speed =0;
	private int player3_hero_option_booster =0;
	private int player3_hero_option_damage =0;
	private int player3_ag = DEFAULT_AG;
	private int player3_speed = DEFAULT_SPEED;
	private int player3_booster = DEFAULT_BOOSTER;
	private int player3_damage = DEFAULT_DAMAGE;
	private String player3_hero = "태희";

	private int player4_hero_option_ag =0;
	private int player4_hero_option_speed =0;
	private int player4_hero_option_booster =0;
	private int player4_hero_option_damage =0;
	private int player4_ag = DEFAULT_AG;
	private int player4_speed = DEFAULT_SPEED;
	private int player4_booster = DEFAULT_BOOSTER;
	private int player4_damage = DEFAULT_DAMAGE;
	private String player4_hero = "태희";

	private String player1Name ="player1";
	private String player2Name ="player2";
	private String player3Name ="player3";
	private String player4Name ="player4";

	private int playerNum;
	private int meter;

	private Intent intent;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setting);
		intent = getIntent();

		player1Btn = (Button)findViewById(R.id.player1Btn);
		player2Btn = (Button)findViewById(R.id.player2Btn);
		player3Btn = (Button)findViewById(R.id.player3Btn);
		player4Btn = (Button)findViewById(R.id.player4Btn);
		nextBtn = (Button)findViewById(R.id.settingNextButton);
		
		mPlay1measureBtn = (Button)findViewById(R.id.player1measureBtn);
		mPlay1measureBtn.setOnClickListener(this);
		mPlay2measureBtn = (Button)findViewById(R.id.player2measureBtn);
		mPlay2measureBtn.setOnClickListener(this);
		mPlay3measureBtn = (Button)findViewById(R.id.player3measureBtn);
		mPlay3measureBtn.setOnClickListener(this);
		mPlay4measureBtn = (Button)findViewById(R.id.player4measureBtn);
		mPlay4measureBtn.setOnClickListener(this);

		player1Btn.setOnClickListener(this);
		player2Btn.setOnClickListener(this);
		player3Btn.setOnClickListener(this);
		player4Btn.setOnClickListener(this);
		nextBtn.setOnClickListener(this);

		t_player1 = (TextView)findViewById(R.id.t_player1);
		t_player2 = (TextView)findViewById(R.id.t_player2);
		t_player3 = (TextView)findViewById(R.id.t_player3);
		t_player4 = (TextView)findViewById(R.id.t_player4);

		s_player1 = (TextView)findViewById(R.id.s_player1);
		s_player2 = (TextView)findViewById(R.id.s_player2);
		s_player3 = (TextView)findViewById(R.id.s_player3);
		s_player4 = (TextView)findViewById(R.id.s_player4);

		b_player1 = (TextView)findViewById(R.id.b_player1);
		b_player2 = (TextView)findViewById(R.id.b_player2);
		b_player3 = (TextView)findViewById(R.id.b_player3);
		b_player4 = (TextView)findViewById(R.id.b_player4);
		
		d_player1 = (TextView)findViewById(R.id.d_player1);
		d_player2 = (TextView)findViewById(R.id.d_player2);
		d_player3 = (TextView)findViewById(R.id.d_player3);
		d_player4 = (TextView)findViewById(R.id.d_player4);

		h_player1 = (TextView)findViewById(R.id.h_player1);
		h_player2 = (TextView)findViewById(R.id.h_player2);
		h_player3 = (TextView)findViewById(R.id.h_player3);
		h_player4 = (TextView)findViewById(R.id.h_player4);

		player1Img = (ImageButton)findViewById(R.id.player1Img);
		player2Img = (ImageButton)findViewById(R.id.player2Img);
		player3Img = (ImageButton)findViewById(R.id.player3Img);
		player4Img = (ImageButton)findViewById(R.id.player4Img);

		init();

		switch(playerNum) {
		case 1: 
			player2Btn.setVisibility(View.INVISIBLE);
			player3Btn.setVisibility(View.INVISIBLE);
			player4Btn.setVisibility(View.INVISIBLE);
			mPlay2measureBtn.setVisibility(View.INVISIBLE);
			mPlay3measureBtn.setVisibility(View.INVISIBLE);
			mPlay4measureBtn.setVisibility(View.INVISIBLE);
			t_player2.setVisibility(View.INVISIBLE);
			t_player3.setVisibility(View.INVISIBLE);
			t_player4.setVisibility(View.INVISIBLE);
			s_player2.setVisibility(View.INVISIBLE);
			s_player3.setVisibility(View.INVISIBLE);
			s_player4.setVisibility(View.INVISIBLE);
			b_player2.setVisibility(View.INVISIBLE);
			b_player3.setVisibility(View.INVISIBLE);
			b_player4.setVisibility(View.INVISIBLE);
			d_player2.setVisibility(View.INVISIBLE);
			d_player3.setVisibility(View.INVISIBLE);
			d_player4.setVisibility(View.INVISIBLE);
			h_player2.setVisibility(View.INVISIBLE);
			h_player3.setVisibility(View.INVISIBLE);
			h_player4.setVisibility(View.INVISIBLE);
			player2Img.setVisibility(View.INVISIBLE);
			player3Img.setVisibility(View.INVISIBLE);
			player4Img.setVisibility(View.INVISIBLE);
			break;
		case 2:
			player3Btn.setVisibility(View.INVISIBLE);
			player4Btn.setVisibility(View.INVISIBLE);
			mPlay3measureBtn.setVisibility(View.INVISIBLE);
			mPlay4measureBtn.setVisibility(View.INVISIBLE);
			t_player3.setVisibility(View.INVISIBLE);
			t_player4.setVisibility(View.INVISIBLE);
			s_player3.setVisibility(View.INVISIBLE);
			s_player4.setVisibility(View.INVISIBLE);
			b_player3.setVisibility(View.INVISIBLE);
			b_player4.setVisibility(View.INVISIBLE);
			d_player3.setVisibility(View.INVISIBLE);
			d_player4.setVisibility(View.INVISIBLE);
			h_player3.setVisibility(View.INVISIBLE);
			h_player4.setVisibility(View.INVISIBLE);
			player3Img.setVisibility(View.INVISIBLE);
			player4Img.setVisibility(View.INVISIBLE);
			break;
		case 3:
			player4Btn.setVisibility(View.INVISIBLE);	
			mPlay4measureBtn.setVisibility(View.INVISIBLE);
			t_player4.setVisibility(View.INVISIBLE);
			s_player4.setVisibility(View.INVISIBLE);
			b_player4.setVisibility(View.INVISIBLE);
			d_player4.setVisibility(View.INVISIBLE);
			h_player4.setVisibility(View.INVISIBLE);
			player4Img.setVisibility(View.INVISIBLE);
		case 4:
			break;
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			Intent i = new Intent(SettingActivity.this, PlayerNumActivity.class);
        	startActivity(i);
        	finish();
			return true;
		} else 
			return false;
	}
	
	public void init() {
		if(!intent.getExtras().getString("player1").equals(""))
			player1Name = intent.getExtras().getString("player1");
		if(!intent.getExtras().getString("player2").equals(""))
			player2Name = intent.getExtras().getString("player2");
		if(!intent.getExtras().getString("player3").equals(""))
			player3Name = intent.getExtras().getString("player3");
		if(!intent.getExtras().getString("player4").equals(""))
			player4Name = intent.getExtras().getString("player4");

		playerNum = intent.getExtras().getInt("playerNum");
		meter = intent.getExtras().getInt("meter");

		player1Btn.setText(player1Name);
		player2Btn.setText(player2Name);
		player3Btn.setText(player3Name);
		player4Btn.setText(player4Name);

		setPlayerInfo();
	}

	public void setPlayerInfo() {
		String option_ag ;
		String option_speed;
		String option_booster;
		String option_damage;
		
		h_player1.setText("Hero : "+player1_hero);
		h_player2.setText("Hero : "+player2_hero);
		h_player3.setText("Hero : "+player3_hero);
		h_player4.setText("Hero : "+player4_hero);

		if(player1_hero_option_ag >=0)
			option_ag ="+"+player1_hero_option_ag;
		else
			option_ag =""+player1_hero_option_ag;
		if(player1_hero_option_speed >=0) 
			option_speed="+"+player1_hero_option_speed;
		else
			option_speed=""+player1_hero_option_speed;
		if(player1_hero_option_booster >=0)
			option_booster ="+"+player1_hero_option_booster;
		else
			option_booster =""+player1_hero_option_booster;
		if(player1_hero_option_damage >=0)
			option_damage ="+"+player1_hero_option_damage;
		else
			option_damage =""+player1_hero_option_damage;
		t_player1.setText("Tick : "+player1_ag+"("+option_ag+")");
		s_player1.setText("Speed : "+player1_speed+"("+option_speed+")");
		b_player1.setText("Booster : "+player1_booster+"("+option_booster+")");
		d_player1.setText("Damage : "+player1_damage+"("+option_damage+")");
		
		if(player2_hero_option_ag >=0)
			option_ag ="+"+player2_hero_option_ag;
		else
			option_ag =""+player2_hero_option_ag;
		if(player2_hero_option_speed >=0) 
			option_speed="+"+player2_hero_option_speed;
		else
			option_speed=""+player2_hero_option_speed;
		if(player2_hero_option_booster >=0)
			option_booster ="+"+player2_hero_option_booster;
		else
			option_booster =""+player2_hero_option_booster;
		if(player2_hero_option_damage >=0)
			option_damage ="+"+player2_hero_option_damage;
		else
			option_damage =""+player2_hero_option_damage;
		t_player2.setText("Tick : "+player2_ag+"("+option_ag+")");
		s_player2.setText("Speed : "+player2_speed+"("+option_speed+")");
		b_player2.setText("Booster : "+player2_booster+"("+option_booster+")");
		d_player2.setText("Damage : "+player2_damage+"("+option_damage+")");
		
		if(player3_hero_option_ag >=0)
			option_ag ="+"+player3_hero_option_ag;
		else
			option_ag =""+player3_hero_option_ag;
		if(player3_hero_option_speed >=0) 
			option_speed="+"+player3_hero_option_speed;
		else
			option_speed=""+player3_hero_option_speed;
		if(player3_hero_option_booster >=0)
			option_booster ="+"+player3_hero_option_booster;
		else
			option_booster =""+player3_hero_option_booster;
		if(player3_hero_option_damage >=0)
			option_damage ="+"+player3_hero_option_damage;
		else
			option_damage =""+player3_hero_option_damage;
		t_player3.setText("Tick : "+player3_ag+"("+option_ag+")");
		s_player3.setText("Speed : "+player3_speed+"("+option_speed+")");
		b_player3.setText("Booster : "+player3_booster+"("+option_booster+")");
		d_player3.setText("Damage : "+player3_damage+"("+option_damage+")");
		
		if(player4_hero_option_ag >=0)
			option_ag ="+"+player4_hero_option_ag;
		else
			option_ag =""+player4_hero_option_ag;
		if(player4_hero_option_speed >=0) 
			option_speed="+"+player4_hero_option_speed;
		else
			option_speed=""+player4_hero_option_speed;
		if(player4_hero_option_booster >=0)
			option_booster ="+"+player4_hero_option_booster;
		else
			option_booster =""+player4_hero_option_booster;
		if(player4_hero_option_damage >=0)
			option_damage ="+"+player4_hero_option_damage;
		else
			option_damage =""+player4_hero_option_damage;
		t_player4.setText("Tick : "+player4_ag+"("+option_ag+")");
		s_player4.setText("Speed : "+player4_speed+"("+option_speed+")");
		b_player4.setText("Booster : "+player4_booster+"("+option_booster+")");
		d_player4.setText("Damage : "+player4_damage+"("+option_damage+")");

		player1Img.setBackgroundResource(imgHero[hero_num.valueOf(player1_hero).ordinal()]);
		player2Img.setBackgroundResource(imgHero[hero_num.valueOf(player2_hero).ordinal()]);
		player3Img.setBackgroundResource(imgHero[hero_num.valueOf(player3_hero).ordinal()]);
		player4Img.setBackgroundResource(imgHero[hero_num.valueOf(player4_hero).ordinal()]);
	}
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(player1Btn.equals(v)) {
			Intent intent = new Intent(SettingActivity.this, SelectHero.class);
			intent.putExtra("row1col1", P1_row1col1Flag);
			intent.putExtra("row1col2", P1_row1col2Flag);
			intent.putExtra("row1col3", P1_row1col3Flag);
			intent.putExtra("row2col1", P1_row2col1Flag);
			intent.putExtra("row2col2", P1_row2col2Flag);
			intent.putExtra("row2col3", P1_row2col3Flag);
			intent.putExtra("row3col1", P1_row3col1Flag);
			intent.putExtra("row3col2", P1_row3col2Flag);
			intent.putExtra("row3col3", P1_row3col3Flag);
			startActivityForResult(intent, 1);
		} else if(player2Btn.equals(v)) {
			Intent intent = new Intent(SettingActivity.this, SelectHero.class);
			intent.putExtra("row1col1", P2_row1col1Flag);
			intent.putExtra("row1col2", P2_row1col2Flag);
			intent.putExtra("row1col3", P2_row1col3Flag);
			intent.putExtra("row2col1", P2_row2col1Flag);
			intent.putExtra("row2col2", P2_row2col2Flag);
			intent.putExtra("row2col3", P2_row2col3Flag);
			intent.putExtra("row3col1", P2_row3col1Flag);
			intent.putExtra("row3col2", P2_row3col2Flag);
			intent.putExtra("row3col3", P2_row3col3Flag);
			startActivityForResult(intent, 2);
		} else if(player3Btn.equals(v)) {
			Intent intent = new Intent(SettingActivity.this, SelectHero.class);
			intent.putExtra("row1col1", P3_row1col1Flag);
			intent.putExtra("row1col2", P3_row1col2Flag);
			intent.putExtra("row1col3", P3_row1col3Flag);
			intent.putExtra("row2col1", P3_row2col1Flag);
			intent.putExtra("row2col2", P3_row2col2Flag);
			intent.putExtra("row2col3", P3_row2col3Flag);
			intent.putExtra("row3col1", P3_row3col1Flag);
			intent.putExtra("row3col2", P3_row3col2Flag);
			intent.putExtra("row3col3", P3_row3col3Flag);
			startActivityForResult(intent, 3);
		} else if(player4Btn.equals(v)) {
			Intent intent = new Intent(SettingActivity.this, SelectHero.class);
			intent.putExtra("row1col1", P4_row1col1Flag);
			intent.putExtra("row1col2", P4_row1col2Flag);
			intent.putExtra("row1col3", P4_row1col3Flag);
			intent.putExtra("row2col1", P4_row2col1Flag);
			intent.putExtra("row2col2", P4_row2col2Flag);
			intent.putExtra("row2col3", P4_row2col3Flag);
			intent.putExtra("row3col1", P4_row3col1Flag);
			intent.putExtra("row3col2", P4_row3col2Flag);
			intent.putExtra("row3col3", P4_row3col3Flag);
			startActivityForResult(intent, 4);
		} else if(mPlay1measureBtn.equals(v)) {
			Intent intent = new Intent(SettingActivity.this, measureActivity.class);
			startActivityForResult(intent, PLAY1_ACT_MESURE_REQUEST); 
		} else if(mPlay2measureBtn.equals(v)) {
			Intent intent = new Intent(SettingActivity.this, measureActivity.class);
			startActivityForResult(intent, PLAY2_ACT_MESURE_REQUEST); 
		} else if(mPlay3measureBtn.equals(v)) {
			Intent intent = new Intent(SettingActivity.this, measureActivity.class);
			startActivityForResult(intent, PLAY3_ACT_MESURE_REQUEST); 
		} else if(mPlay4measureBtn.equals(v)) {
			Intent intent = new Intent(SettingActivity.this, measureActivity.class);
			startActivityForResult(intent, PLAY4_ACT_MESURE_REQUEST); 
		} else {
			final View dialog = View.inflate(getApplicationContext(), R.layout.penalty, null); 
			final AlertDialog panaltyAD = new AlertDialog.Builder(SettingActivity.this).setPositiveButton("ok", new DialogInterface.OnClickListener() {

				public void onClick(DialogInterface arg0, int arg1) {
					// TODO Auto-generated method stub
					//player name을 입력받는 변수
					String first = ((EditText)dialog.findViewById(R.id.firstEdit)).getText().toString();
					String second = ((EditText)dialog.findViewById(R.id.secondEdit)).getText().toString();
					String third = ((EditText)dialog.findViewById(R.id.thirdEdit)).getText().toString();
					String fourth = ((EditText)dialog.findViewById(R.id.fourthEdit)).getText().toString();


					Intent startIntent = new Intent(SettingActivity.this, main.class);

					startIntent.putExtra("player1Name", player1Name);
					startIntent.putExtra("player2Name", player2Name);
					startIntent.putExtra("player3Name", player3Name);
					startIntent.putExtra("player4Name", player4Name);

					startIntent.putExtra("first", first);
					startIntent.putExtra("second", second);
					startIntent.putExtra("third", third);
					startIntent.putExtra("foruth", fourth);

					startIntent.putExtra("player1_ag", player1_ag+player1_hero_option_ag);
					startIntent.putExtra("player2_ag", player2_ag+player2_hero_option_ag);
					startIntent.putExtra("player3_ag", player3_ag+player3_hero_option_ag);
					startIntent.putExtra("player4_ag", player4_ag+player4_hero_option_ag);

					startIntent.putExtra("player1_speed", player1_speed+player1_hero_option_speed);
					startIntent.putExtra("player2_speed", player2_speed+player2_hero_option_speed);
					startIntent.putExtra("player3_speed", player3_speed+player3_hero_option_speed);
					startIntent.putExtra("player4_speed", player4_speed+player4_hero_option_speed);

					startIntent.putExtra("player1_booster", player1_booster+player1_hero_option_booster);
					startIntent.putExtra("player2_booster", player2_booster+player2_hero_option_booster);
					startIntent.putExtra("player3_booster", player3_booster+player3_hero_option_booster);
					startIntent.putExtra("player4_booster", player4_booster+player4_hero_option_booster);
					
					startIntent.putExtra("player1_damage", player1_damage+player1_hero_option_damage);
					startIntent.putExtra("player2_damage", player2_damage+player2_hero_option_damage);
					startIntent.putExtra("player3_damage", player3_damage+player3_hero_option_damage);
					startIntent.putExtra("player4_damage", player4_damage+player4_hero_option_damage);

					startIntent.putExtra("player1_hero", player1_hero);
					startIntent.putExtra("player2_hero", player2_hero);
					startIntent.putExtra("player3_hero", player3_hero);
					startIntent.putExtra("player4_hero", player4_hero);

					startIntent.putExtra("playerNum", playerNum);
					startIntent.putExtra("meter", meter);

					startActivity(startIntent);
					finish();
				}

			}).setView(dialog).setTitle("Panalty Input").create();         
			//plyer name을 입력하는 Linear Layout
			ViewGroup panalty2 = (ViewGroup)dialog.findViewById(R.id.panalty2);
			ViewGroup panalty3 = (ViewGroup)dialog.findViewById(R.id.panalty3);
			ViewGroup panalty4 = (ViewGroup)dialog.findViewById(R.id.panalty4);				

			//player number에 따라 입력하는 editview의 개수를 조절
			switch(playerNum) {
			case 3:
				panalty4.setVisibility(View.INVISIBLE);
				break;
			case 2:
				panalty3.setVisibility(View.INVISIBLE);
				panalty4.setVisibility(View.INVISIBLE);
				break;
			case 1:
				panalty2.setVisibility(View.INVISIBLE);
				panalty3.setVisibility(View.INVISIBLE);
				panalty4.setVisibility(View.INVISIBLE);
				break;
			}
			panaltyAD.show();
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		switch(requestCode) {
		case 1:
			if(resultCode == RESULT_OK) {
				player1_hero_option_ag = data.getIntExtra("ag", 0);
				player1_hero_option_speed = data.getIntExtra("speed", 0);
				player1_hero_option_booster = data.getIntExtra("booster", 0);
				player1_hero_option_damage = data.getIntExtra("damage", 0);
				player1_hero = data.getStringExtra("name");
				setPlayerInfo();
			}
			break;
		case 2:
			if(resultCode == RESULT_OK) {
				player2_hero_option_ag = data.getIntExtra("ag", 0);
				player2_hero_option_speed = data.getIntExtra("speed", 0);
				player2_hero_option_booster = data.getIntExtra("booster", 0);
				player2_hero_option_damage = data.getIntExtra("damage", 0);
				player2_hero = data.getStringExtra("name");
				setPlayerInfo();
			}
			break;
		case 3:
			if(resultCode == RESULT_OK) {
				player3_hero_option_ag = data.getIntExtra("ag", 0);
				player3_hero_option_speed = data.getIntExtra("speed", 0);
				player3_hero_option_booster = data.getIntExtra("booster", 0);
				player3_hero_option_damage = data.getIntExtra("damage", 0);
				player3_hero = data.getStringExtra("name");
				setPlayerInfo();
			}
			break;
		case 4:
			if(resultCode == RESULT_OK) {
				player4_hero_option_ag = data.getIntExtra("ag", 0);
				player4_hero_option_speed = data.getIntExtra("speed", 0);
				player4_hero_option_booster = data.getIntExtra("booster", 0);
				player4_hero_option_damage = data.getIntExtra("damage", 0);
				player4_hero = data.getStringExtra("name");
				setPlayerInfo();
			}
			break;
		case PLAY1_ACT_MESURE_REQUEST:
			if(resultCode == RESULT_OK) {
				P1_row1col1Flag = data.getBooleanExtra("row1col1",false);
				P1_row1col2Flag = data.getBooleanExtra("row1col2",false);
				P1_row1col3Flag = data.getBooleanExtra("row1col3",false);
				P1_row2col1Flag = data.getBooleanExtra("row2col1",false);
				P1_row2col2Flag = data.getBooleanExtra("row2col2",true);
				P1_row2col3Flag = data.getBooleanExtra("row2col3",false);
				P1_row3col1Flag = data.getBooleanExtra("row3col1",false);
				P1_row3col2Flag = data.getBooleanExtra("row3col2",false);
				P1_row3col3Flag = data.getBooleanExtra("row3col3",false);
			}
			break;
		case PLAY2_ACT_MESURE_REQUEST:
			if(resultCode == RESULT_OK) {
				P2_row1col1Flag = data.getBooleanExtra("row1col1",false);
				P2_row1col2Flag = data.getBooleanExtra("row1col2",false);
				P2_row1col3Flag = data.getBooleanExtra("row1col3",false);
				P2_row2col1Flag = data.getBooleanExtra("row2col1",false);
				P2_row2col2Flag = data.getBooleanExtra("row2col2",true);
				P2_row2col3Flag = data.getBooleanExtra("row2col3",false);
				P2_row3col1Flag = data.getBooleanExtra("row3col1",false);
				P2_row3col2Flag = data.getBooleanExtra("row3col2",false);
				P2_row3col3Flag = data.getBooleanExtra("row3col3",false);
			}
			break;
		case PLAY3_ACT_MESURE_REQUEST:
			if(resultCode == RESULT_OK) {
				P3_row1col1Flag = data.getBooleanExtra("row1col1",false);
				P3_row1col2Flag = data.getBooleanExtra("row1col2",false);
				P3_row1col3Flag = data.getBooleanExtra("row1col3",false);
				P3_row2col1Flag = data.getBooleanExtra("row2col1",false);
				P3_row2col2Flag = data.getBooleanExtra("row2col2",true);
				P3_row2col3Flag = data.getBooleanExtra("row2col3",false);
				P3_row3col1Flag = data.getBooleanExtra("row3col1",false);
				P3_row3col2Flag = data.getBooleanExtra("row3col2",false);
				P3_row3col3Flag = data.getBooleanExtra("row3col3",false);
			}
			break;
		case PLAY4_ACT_MESURE_REQUEST:
			if(resultCode == RESULT_OK) {
				P4_row1col1Flag = data.getBooleanExtra("row1col1",false);
				P4_row1col2Flag = data.getBooleanExtra("row1col2",false);
				P4_row1col3Flag = data.getBooleanExtra("row1col3",false);
				P4_row2col1Flag = data.getBooleanExtra("row2col1",false);		
				P4_row2col2Flag = data.getBooleanExtra("row2col2",true);
				P4_row2col3Flag = data.getBooleanExtra("row2col3",false);
				P4_row3col1Flag = data.getBooleanExtra("row3col1",false);
				P4_row3col2Flag = data.getBooleanExtra("row3col2",false);
				P4_row3col3Flag = data.getBooleanExtra("row3col3",false);
			}
			break;
		}
	}

}
